# import logging
#
# from django.dispatch import receiver
# from django.db.models.signals import post_save
#
# from erp_system.models import Menu, PermissionsModel
#
# # 默认情况下，每一个功能菜单的接口的请求方法数量
# methods = {'POST': '新增', 'GET': '查询', 'PUT': '修改', 'DELETE': '删除', 'PATCH': '局部修改'}
#
# logger = logging.getLogger('my')
#
#
# @receiver(post_save, sender=Menu)
# def create_menus_permissions(sender, instance, created, **kwargs):
#     """
#     当有人新增一个功能菜单（Menu)之后， 需要把该功能菜单对应的权限也插入到数据库
#     :param sender:
#     :param instance:
#     :param created:
#     :param kwargs:
#     :return:
#     """
#
#     if created:
#         logger.info('Menu对象已经新增完成了！')
#         if isinstance(instance, Menu):
#             if not instance.parent:  # 表示是一个顶级菜单，没有请求URL地址，不是一个接口
#                 permission = PermissionsModel.objects.create(
#                     name=instance.name + "的权限",
#                     is_menu=True,
#                     menu=instance
#                 )
#             else:  # 表示是接口：有父菜单，有请求的url地址
#                 for method in methods:
#                     permission = PermissionsModel.objects.create(
#                         name=methods.get(method) + "的权限",
#                         is_menu=False,
#                         menu=instance,
#                         method=method,
#                         path=instance.url,
#                         desc=f'{instance.name}的{methods.get(method)}的权限'
#                     )
#         else:
#             logger.info('instance不是Menu类型，所以不需要任何处理')
